/*=+--+=#=+--     Unmanned Aerial System Management Software      --+=#=+--+=#*\
|          Copyright (C) 2011 Regents of the University of Colorado.           |
|                             All Rights Reserved.                             |

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2 as
     published by the Free Software Foundation.

     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with this program.  If not, see <http://www.gnu.org/licenses/>.

            Jack Elston                       Cory Dixon                        
|           elstonj@colorado.edu              dixonc@colorado.edu              |
|                                                                              |
\*=+--+=#=+--                 --+=#=+--+=#=+--                    --+=#=+--+=#*/

/*!
  \file socketThread.h
	\brief header file for internet socket thread receiving data

                    \author Jack Elston
             $Date: 2005/02/12 00:20:45 $
*/
#ifndef __SERIALTHREAD_H
#define __SERIALTHREAD_H

#include <unistd.h>
#include <signal.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <arpa/inet.h>

#include "String.h"
#include "serial.h"
#include "timeLib.h"
#include "type_defs.h"
#include "threadedPipe.h"
#include "shmStruct.h"

//////////////////////////////////////////
// Thread classes
//////////////////////////////////////////
class SerialThread : public ThreadedPipe
{
	private:
		SerialPort *serial;
		volatile bool Connected_serial;
		int waitCount_serial;
		int badReadCount;

		String devStr;
		String baudStr;

		int read();
		int write(int num);

	public:
		SerialThread(String name,
				String dev="/dev/ttyS0",
				String baud="57600");

		~SerialThread()
			{ if( serial != NULL) delete serial; }

		void update();
		void close();
};

#endif
